import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:niuren_demo/configs/App_style_config.dart';
import 'package:niuren_demo/view/text/text_style.dart';

class EditPage extends StatefulWidget {
  @override
  _EditPageState createState() => _EditPageState();
}

class _EditPageState extends State<EditPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: buildAppBar(),
      body: Container(
        padding: EdgeInsets.symmetric(horizontal: 16),
        child: Column(
          children: [
            buildImage(
              title: "头像",
              imageurl:
                  "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201808%2F15%2F20180815112431_keyzi.thumb.700_0.jpeg&refer=http%3A%2F%2Fb-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1617851642&t=7b6a7c66ce19ae61adcdf25c8c3b8856",
            ),
            buildImage(
              title: "背景",
              imageurl:
                  "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fc-ssl.duitang.com%2Fuploads%2Fitem%2F202004%2F12%2F20200412095043_mcups.jpg&refer=http%3A%2F%2Fc-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1618562336&t=b33963960406af202b532b051943cb00",
            ),
            buildInformation(title: "性别", information: "男"),
            buildInformation(title: "城市", information: "广东/珠海"),
            buildAutograph(),
            buildButton(),
          ],
        ),
      ),
    );
  }

  Widget buildAppBar() {
    return AppBar(
      backgroundColor: AppStyleConfig.themColor,
      centerTitle: true,
      title: Text(
        "编辑主页",
        style: TextStyle(color: Colors.white),
      ),
    );
  }

  Widget buildImage({String title, String imageurl}) {
    return Container(
      height: 70,
      padding: EdgeInsets.symmetric(horizontal: 10, vertical: 10),
      decoration: BoxDecoration(
        border: Border(bottom: BorderSide(color: Colors.grey[200], width: 1)),
      ),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        crossAxisAlignment: CrossAxisAlignment.end,
        children: [
          Text_style(
            data: title,
            color: Colors.black,
            fontSize: 18,
          ),
          Container(
            width: 40,
            height: 40,
            decoration: BoxDecoration(
              borderRadius: BorderRadius.all(
                Radius.circular(2),
              ),
              image: DecorationImage(
                image: NetworkImage(
                  imageurl,
                ),
                fit: BoxFit.cover,
              ),
            ),
          ),
        ],
      ),
    );
  }

  Widget buildInformation({String title, String information}) {
    return Container(
      height: 70,
      padding: EdgeInsets.symmetric(horizontal: 10, vertical: 10),
      decoration: BoxDecoration(
        border: Border(bottom: BorderSide(color: Colors.grey[200], width: 1)),
      ),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        crossAxisAlignment: CrossAxisAlignment.end,
        children: [
          Text_style(
            data: title,
            color: Colors.black,
            fontSize: 18,
          ),
          Text_style(
            data: information,
            color: Colors.grey,
            fontSize: 16,
          ),
        ],
      ),
    );
  }

  Widget buildAutograph() {
    return Container(
      margin: EdgeInsets.only(top: 20),
      padding: EdgeInsets.symmetric(horizontal: 10,),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            "签名",
            style: TextStyle(
                fontSize: 18,),
          ),
          Container(
            margin: EdgeInsets.only(top: 10),
            padding: EdgeInsets.symmetric(vertical: 8),
            height: 200,
            decoration: BoxDecoration(
              color: Colors.white,
              border: Border.all(width: 0.5, color: Colors.grey[200]),
              borderRadius: BorderRadius.all(
                Radius.circular(4),
              ),
            ),
            child: TextField(
              keyboardType: TextInputType.multiline,
              style: TextStyle(fontSize: 18),
              maxLines: 5,
              minLines: 1,
              cursorColor: AppStyleConfig.themColor,
              decoration: const InputDecoration(
                  hintText: '请输入个性签名',
                  hintStyle: TextStyle(
                      fontSize: 14, color: Colors.grey),
                  filled: true,
                  fillColor: Colors.white,
                  contentPadding:
                      const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
                  isDense: true,
                  border: InputBorder.none),
            ),
          ),
        ],
      ),
    );
  }

  Widget buildButton(){
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 10,),
      margin: EdgeInsets.only(top: 30),
      child: Row(
        children: [
          Expanded(flex:1,child: Container(alignment:Alignment.center,height:40,color:Colors.grey,child: Text("取消",style: TextStyle(color: Colors.white,fontSize: 18),),),),
          SizedBox(width: 30,),
          Expanded(flex:1,child: Container(alignment:Alignment.center,height:40,color:AppStyleConfig.themColor,child: Text("保存",style: TextStyle(color: Colors.white,fontSize: 18),),),),
        ],
      ),
    );
  }
}
